
    var btnFlag = true 
; $(function ()      {
    //加载读取cookie数据加载到页面
    var users = JSON.parse(($.cookie("userinfo"))||"{}");
    $(".username").val(users.uname);
    $(".userpwd").val(users.upwd);
    $("#remeber").attr("checked", "checked");
    //滑块验证
    var $yanzhengbtn = $(".yanzhengbtn");
    function drag($dom) {
        $dom.on("mousedown", function (e) {
            var disX = e.clientX - $(this).offset().left;
            $dom.parent().on("mousemove", function (e) {
                var $hideyangzhengbox = $(".hideyangzhengbox");
                $("#codetxt").css({ "z-index": 999999 });
                $(".hideyangzhengbox").css({ "z-index": 10 });
                var $yangzhengbox = $(".yangzhengbox");
                var left = e.clientX - disX - $dom.parent().offset().left;
                if (left < 50) {
                    left = 0;
                    $hideyangzhengbox.css("left", -$hideyangzhengbox.css("width"))
                }
                if (left > $dom.parent().width() - $dom.width() - 30) {
                    left = $dom.parent().width() - $dom.width() - 2;
                    $hideyangzhengbox.css("left", 0)
                    $(this).off("mousemove");
                }
                $dom.css("left", left);
                $hideyangzhengbox.css("left", -parseInt($hideyangzhengbox.css("width")) +
                    left)
                $(document).on("mouseup", function () {
                    if (left < $dom.parent().width() / 1.25) {
                        left = 0;
                        $hideyangzhengbox.css("left", -parseInt($hideyangzhengbox
                            .css("width")));
                    } else {
                        left = $dom.parent().width() - $dom.width() - 2;
                        $hideyangzhengbox.css("left", 0)
                    }
                    $dom.css("left", left);
                    if ($dom.position().left == $dom.parent().width() - $dom
                        .width() - 1.2) {
                        $hideyangzhengbox.text("验证通过");
                        $hideyangzhengbox.css({
                            "color": "#fff",
                            "font-size": '12px'
                        });
                        var yanzhengbtn = document.querySelector(".yanzhengbtn");

                        $yanzhengbtn.text("");
                        yanzhengbtn.classList.add("succ")
                        $("#codetxt").hide();
                        btnFlag = true;
                    }
                    $dom.parent().off("mousemove");
                    $dom.parent().off("mouseup");
                })
            })
        })
    }
    drag($yanzhengbtn);

    //点击按钮提交
    $("#butn").on("click", function () {
        var $unameval = $(".username").val()
        var $upwdval = $(".userpwd").val();
        if ($unameval == "") {
            $(".unameTxt").addClass("uname-error");
            $(".unameTxt").text("请输入用户名~~");
        } else {
            $(".unameTxt").removeClass("uname-error");
            $(".unameTxt").text("");
            //密码为空
            if ($upwdval == "") {
                $(".upwdTxt").addClass("uname-error");
                $(".upwdTxt").text("请输入密码~~");
            } else {
                $(".upwdTxt").removeClass("uname-error");
                $(".upwdTxt").text("");
            }
            //滑块解锁
            if (btnFlag == false) {
                $(".btnTxt").addClass("uname-error");
                $(".btnTxt").text("请进行滑块验证~~");
                return false;
            } else {
                $(".btnTxt").removeClass("uname-error");
                $(".btnTxt").text("");
            }
        }
        //发送ajax请求
        $.ajax({
            url: "../../api/login",
            data: {
                uname: $unameval,
                upwd: $upwdval
            },
            type: "post",
            dataType: "json"
        }).then((data) => {

            if (data.status == 1) {
                var saveObj = {
                    uname: $unameval,
                    upwd: $upwdval,
                    uId: data.data.uId
                }
                if ($("#remeber").attr("checked", "checked")) {
                    $.cookie("userinfo", JSON.stringify(saveObj), 999);
                           window.location = "./loginafter.html"
                }else{
                    $.cookie("userinfo","",-1);
                }
            } else {
                layer.msg("登录失败,用户名或密码错误");
                $(".unameTxt").addClass("uname-error");
                $(".unameTxt").text("用户名或密码错误~~");
                return false;
            }
        })
        return false;
    })

})